﻿using Loki.Model;
using Loki.Utils;

namespace Loki.Engine
{
    public abstract class ApplicationService<TModel, TDataContext> : LokiService, IDataContextAware<TDataContext>, IApplicationService<TModel>
    {
        #region Model
        /// <summary>
        /// Gets the application model.
        /// </summary>
        /// <value>
        /// The application model.
        /// </value>
        public virtual TModel ApplicationModel
        {
            get { return ContextHelper.GetApplicationModel<TModel>(); }
        }

        public virtual TDataContext DataContext
        {
            get { return ContextHelper.GetDataModel<TDataContext>(); }
        }

        #endregion

        protected EntityContainer<TEntity, TKey> CreateContainer<TEntity, TKey>(ContainerConfiguration<TEntity, TKey> P_Configuration)
            where TEntity : IAtomicEntity<TKey>
        {
            EntityContainer<TEntity, TKey> L_Container = new EntityContainer<TEntity, TKey>(P_Configuration);
            RegisterDisposable(L_Container);
            return L_Container;
        }

        protected EntityLinkContainer<TKey> CreateLinkContainer<TKey>(LinkContainerConfiguration<TKey> P_Configuration)
        {
            EntityLinkContainer<TKey> L_Container = new EntityLinkContainer<TKey>(P_Configuration);
            RegisterDisposable(L_Container);
            return L_Container;
        }
    }
}
